//
//  HESearchHealthCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/17.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HESearchHealthCell.h"
#import "HESearchDataModel.h"

@interface HESearchHealthCell ()

@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *descLb;

@end

@implementation HESearchHealthCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

- (void)initUI {
    UIView *warp = [UIView new];
    [self.contentView addSubview:warp];

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(0);
        make.right.equalTo(self.contentView).mas_offset(0);
        make.height.mas_greaterThanOrEqualTo(130);
        make.bottom.equalTo(self.contentView).mas_offset(0);
    }];
    
    _goodsimgView = [UIImageView new];
    _goodsimgView.image = IMAGE_NAMED(@"noImage");
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];
    _goodsimgView.layer.masksToBounds = YES;
    _goodsimgView.layer.cornerRadius = 6.0;

    _titleLb = [UILabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYBlodFont(17);
    _titleLb.numberOfLines = 2;
    [warp addSubview:_titleLb];
    
    _descLb = [UILabel new];
    _descLb.text = @"-";
    _descLb.font = DYFont(15);
    _descLb.numberOfLines = 3;
    _descLb.textColor = CNavDargGrayColor;
    [warp addSubview:_descLb];
    
    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).mas_offset(15);
        make.left.equalTo(warp).mas_offset(15);
        make.width.height.mas_offset(100);
    }]; 
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodsimgView.mas_top);
        make.left.equalTo(_goodsimgView.mas_right).mas_offset(11);
        make.right.equalTo(warp.mas_right).mas_offset(-10);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    
    [_descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_goodsimgView.mas_right).mas_offset(11);
        make.right.equalTo(warp).mas_offset(-10);
        make.bottom.equalTo(warp).mas_offset(-10);
    }];
}

- (void)configCellWithModel:(id)model {    
    HESearchDataItemModel *item = (HESearchDataItemModel *)model;
    _titleLb.text = item.title;
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:item.img_url] placeholderImage:IMAGE_NAMED(@"noImage")];
    _descLb.text = item.sub_title;
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
